package io.github.junxworks.qt.modules.data.utils;

import java.math.BigDecimal;

/**
 * @program :springbootdev
 * @description:
 * @author:Junxworks
 * @create:2019-08-17 11:23
 */
public class CommStringUtils
{
    public static Long toLong(String str , Long defVal)
    {
        if(isEmpty(str))
        {
            return defVal ;
        }
        Long result = null ;
        try
        {
            result = Long.valueOf(str);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            result=defVal ;
        }
        return result ;
    }
    public static BigDecimal toBigDecimal(String str , BigDecimal defVal)
    {
        if(isEmpty(str))
        {
            return defVal ;
        }
        BigDecimal result = null ;
        try
        {
            result = new BigDecimal(str);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            result=defVal ;
        }
        return result ;
    }
    public static Integer toInteger (String str , Integer defVal)
    {
        if(isEmpty(str))
        {
            return defVal ;
        }
        Integer result = null ;
        try
        {
            result = Integer.valueOf(str);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            result=defVal ;
        }
        return result ;
    }

    public static boolean isEmpty(Object str) {
        return (str == null || "".equals(str));
    }
}
